home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / ext / IC / InternetConfig.xs < prev    next >
Encoding:
Text File  |  1995-03-08  |  2.1 KB  |  115 lines  |  [TEXT/MPS ]

  1. /* $Header: tyrathect:Development:Perl::RCS:missing.c,v 1.2 1994/05/04 02:12:43 neeri Exp $
  2.  *
  3.  *    Copyright (c) 1995 Matthias Neeracher
  4.  *
  5.  *    You may distribute under the terms of the Perl Artistic License,
  6.  *    as specified in the README file.
  7.  *
  8.  * $Log: missing.c,v $
  9.  */
  10.  
  11. #include "EXTERN.h"
  12. #include "perl.h"
  13. #include "XSUB.h"
  14. #include <ICAPI.h>
  15.  
  16. typedef ICInstance InternetConfig;
  17.  
  18. /* This prevents nested InternetConfig iterators. So what */
  19.  
  20. static int ICIter = 0;
  21.  
  22. MODULE = InternetConfig    PACKAGE = InternetConfig    PREFIX = IC_
  23.  
  24. void
  25. IC_TIEHASH(dbtype)
  26.     char *    dbtype
  27.     CODE:
  28.     {
  29.             InternetConfig    ic;
  30.             ST(0) = sv_newmortal();
  31.             if (!ICStart(&ic, 'McPL')) {
  32.         sv_setref_pv(ST(0), "InternetConfig", (void*)ic);
  33.         ICFindConfigFile(ic, 0, nil);
  34.         }
  35.         }
  36.  
  37.  
  38. void
  39. IC_DESTROY(ic)
  40.     InternetConfig    ic
  41.     CODE:
  42.     ICStop(ic);
  43.  
  44. void
  45. IC_FETCH(ic, key)
  46.     InternetConfig    ic
  47.     Str255        key
  48.     CODE:
  49.     {
  50.         ICAttr    attr;
  51.         long    size;
  52.         
  53.             ST(0) = sv_newmortal();
  54.         switch (ICGetPref(ic, key, &attr, nil, &size)) {
  55.         case icTruncatedErr:
  56.         case 0:
  57.             ICGetPref(ic, key, &attr, sv_grow(ST(0), size + 1), &size);
  58.             SvCUR(ST(0)) = size;
  59.             *SvEND(ST(0)) = '\0';
  60.             (void)SvPOK_only(ST(0));        /* validate pointer */
  61.         break;
  62.         }
  63.         ICEnd(ic);
  64.     }
  65.  
  66. void
  67. IC_STORE(ic, key, value, flags)
  68.     InternetConfig    ic
  69.     Str255        key
  70.     char *        value
  71.     int        flags
  72.         CODE:
  73.     {
  74.         ICSetPref(ic, key, 0, SvPVX(ST(2)), SvCUR(ST(2)));
  75.         ICEnd(ic);        
  76.     }
  77.  
  78. void
  79. IC_DELETE(ic, key)
  80.     InternetConfig    ic
  81.     Str255        key
  82.         CODE:
  83.     {
  84.         ICBegin(ic, icReadWritePerm);
  85.         ICDeletePref(ic, key);
  86.         ICEnd(ic);        
  87.     }
  88.  
  89. void
  90. IC_FIRSTKEY(ic)
  91.     InternetConfig    ic
  92.     CODE:
  93.     {
  94.         Str255 key;
  95.         
  96.         ICBegin(ic, icReadOnlyPerm);
  97.             ST(0) = sv_newmortal();
  98.         if (!ICGetIndPref(ic, ICIter = 1, key))
  99.         sv_setpvn(ST(0), ((char *) key) + 1, key[0]);
  100.         ICEnd(ic);
  101.     }
  102.  
  103. char *
  104. IC_NEXTKEY(ic, key)
  105.     InternetConfig    ic
  106.     Str255        key
  107.     CODE:
  108.     {
  109.             ST(0) = sv_newmortal();
  110.         ICBegin(ic, icReadOnlyPerm);
  111.         if (!ICGetIndPref(ic, ++ICIter, key))
  112.         sv_setpvn(ST(0), ((char *) key) + 1, key[0]);
  113.         ICEnd(ic);
  114.     }
  115.